<div class="row" >
    <div class="form-group">
        <input type="hidden" id='user_review_id' value="<?php echo $profiles->user_id; ?>">
        <input type="hidden" id='user_review_userType' value="<?php echo $userType; ?>">
        <textarea class="form-control review-form"  placeholder="Write your review" style="min-height:166px" name="TrainerProfileReview['reviews_text']" id="reviews_text" onkeyup ="reviewTextcountChar(this);"></textarea>
        <div class="errorMessage" id="error_reviews_text" ></div>
        <div class="reviews_text_success errorMessage" id="reviews_text_success"></div>
        <div id="charNum" class="errorMessage"></div></div>                  
    <input type="submit" class="btn review-btn" id="submitLbtR" value="submit">
    <span href="#" class="review-btn" id="review-dismis">cancel</span>
    <div id="reviewLoder" style="display: none"><img  class="reviewloader"src="<?php echo ThemePath(); ?>/images/myskill.gif"></img></div> 
</div>
<script>
            function reviewTextcountChar(val) {
                var len = val.value.length;
                if (len <= 50) {
                    $('#charNum').text('You can type min 50 char.'); 
                }
                if (len >= 600) {
                    val.value = val.value.substring(0, 600);
                    $('#charNum').text('You can type max 600 char.');
                } else {
                    $('#charNum').text('');
                }
            }
</script>
<script>
    $("#submitLbtR").click(function() {
        var text = $("#reviews_text").val();
        var userId = $("#user_review_id").val();
        var userType = $("#user_review_userType").val();
        if (text == '') {
            $("#error_reviews_text").text('Please Write Your Review.');
        } else {
          var result=countChar(reviews_text);
       if(result!=false){
         jQuery.ajax({
                'type': 'POST',
                'url': "<?php echo Yii::app()->createUrl("TrainerProfileReview/create"); ?>",
                'data': "YII_CSRF_TOKEN=" + $('input[name="YII_CSRF_TOKEN"]').val() + "&userId=" + userId + "&text=" + text + "&userType=" + userType,
                'beforeSend': function(jqXHR, settings) {
                    $("#reviewLoder").show();
                },
                'success': function(result) {                  
                    $("#reviewLoder").hide();
                    if ($.trim(result) == 'redirect') {
                        window.location = "#top-position";
                        $('#login-panel').slideToggle();
                        return false;
                    }
                    if ($.trim(result) == 'againsameuser') {
                        $("#reviews_text_success").hide();
                        $("#reviewDiv").hide();
                        $("#reviewEntryBox").show();
                        $("#error_reviews_text").show();
                        $("#error_reviews_text").text("You you have already made a query for this trainer.").show();
                        return false;
                    }

                    if ($.trim(result) == 'fail') {
                        $("#error_reviews_text").text("You can't give own review.");
                    }
                    else {                        
                       // $(".add-review").hide();
                        $("#reviews_text_success").text(result);
                    }
                },
                'cache': false
            });

        }}
    })

</script>

